home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / General tools / Audit app & dcmd / Src / TextEditManager.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  4.6 KB  |  162 lines  |  [TEXT/KAHL]

  1. /*                                TextEditManager.h                                */
  2. /*
  3.  * TextEditManager.h
  4.  * Copyright © 1993 Apple Computer Inc. All rights reserved.
  5.  *
  6.  * These functions manage a TextEdit field (comparable to an EditText item in a
  7.  * dialog. This module is intentionally more-or-less self-contained so it can
  8.  * easily be exported to other applications. It is extremely limited: it does
  9.  * not support styles, scrolling, or other niceties. It does, however, support
  10.  * Undo.
  11.  */
  12. #ifndef __TextEditManager__
  13. #define __TextEditManager__
  14. #ifndef THINK_C                /* MPW includes            */
  15. #include <Errors.h>
  16. #include <Script.h>
  17. #include <Types.h>
  18. #include <Resources.h>
  19. #include <QuickDraw.h>
  20. #include <Fonts.h>
  21. #include <Events.h>
  22. #include <Windows.h>
  23. #include <ToolUtils.h>
  24. #include <Memory.h>
  25. #include <TextEdit.h>
  26. #endif
  27. /*
  28.  * Usage:
  29.  *        EditHandle                    CreateEditHandle(
  30.  *                const Rect                *viewRect,
  31.  *                short                    fontNumber,
  32.  *                short                    fontSize,
  33.  *                short                    editMenuID,
  34.  *                short                    undoTextResID,
  35.  *                void                    *refCon
  36.  *            );
  37.  *    Create a TextEdit record. Return NULL on problems. The Handle returned
  38.  *    locates a private structure that will contain the TextEdit handle and
  39.  *    some information needed to support Undo. Applications access the
  40.  *    actual TextEdit handle by calling GetTEHandle(theEditHandle). The
  41.  *    undoTextResID is the id of a 'STR#' resource with the following text:
  42.  *            Undo
  43.  *            UndoTyping
  44.  *            UndoCut
  45.  *            UndoCopy
  46.  *            UndoPaste
  47.  *            UndoClear
  48.  *            RedoTyping
  49.  *            RedoCut
  50.  *            RedoCopy
  51.  *            RedoPaste
  52.  *            RedoClear
  53.  *
  54.  *        void                        DisposeEditHandle(
  55.  *                EditHandle                editHandle
  56.  *            );
  57.  * Dispose of the TextEdit handle and all of the auxiliary structures.
  58.  *
  59.  * The application calls the following routines as necessary, passing the
  60.  * result of GetTEHandle.
  61.  *        TEActivate            Activate the TextEdit Record
  62.  *        TEDeactivate        Deactivate the TextEdit Record
  63.  *        TEGetText, etc.    Manipulate the text as needed. Note: cut, copy,
  64.  *                paste, and the various insert operations must be handled
  65.  *                by EditHandle functions in order to support Undo. DoEditEvent
  66.  *                does as much of this as possible.
  67.  *
  68.  *        Boolean                        DoTextEditEvent(
  69.  *                EditHandle                editHandle,
  70.  *                const EventRecord        *eventRecord
  71.  *            );
  72.  *    Called on any event (even null events). It returns TRUE if it processed the
  73.  *    event: mouseDown (in the TextEdit viewRect), keyDown.
  74.  *
  75.  *        Boolean                        AdjustEditMenu(
  76.  *                EditHandle                editHandle
  77.  *            );
  78.  * Called to setup the edit menu. It must have the standard item structure:
  79.  *        "Undo;(-;Cut;Copy;Paste;(-;Clear"
  80.  * Returns TRUE if this text edit item was active. Otherwise, it does nothing.
  81.  *
  82.  *        void                        RepositionEditItem(
  83.  *                EditHandle                editHandle,
  84.  *                const Rect                *viewRect
  85.  *            );
  86.  *    Called to move and resize the EditHandle datum. Called after the window is
  87.  *    redecorated.
  88.  *        Boolean                        ManageEditMenu(
  89.  *                EditHandle                editHandle,
  90.  *                short                    menuItem
  91.  *            );
  92.  *    Called when an Edit Menu item is selected. Returns TRUE if this edit
  93.  *    menu item was active, otherwise, it does nothing. This function performs
  94.  *    Cut/Copy/Paste/Clear and Undo actions.
  95.  */
  96.  
  97.  
  98. /*
  99.  * The order of the following must track the order of the Undo text STR#
  100.  */
  101. typedef enum UndoAction {
  102.     kUndoUnknown = 0,
  103.     kUndoByItself,
  104.     kUndoTyping,
  105.     kUndoCut,
  106.     kUndoCopy,
  107.     kUndoPaste,
  108.     kUndoClear,
  109.     kRedoTyping,
  110.     kRedoCut,
  111.     kRedoCopy,
  112.     kRedoPaste,
  113.     kRedoClear,
  114.     kUndoOffset = (kRedoTyping - kUndoTyping)
  115. } UndoAction;
  116.  
  117. typedef struct EditRecord {
  118.     TEHandle                    teHandle;        /* User's TextEdit handle        */
  119.     Handle                        undoHandle;        /* Undone stuff stored here        */
  120.     unsigned short                undoSelStart;    /* SelStart of undone stuff        */
  121.     unsigned short                undoSelEnd;        /* SelEnd of undone stuff        */
  122.     Boolean                        newUndo;        /* TRUE to start a sequence        */
  123.     short                        editMenuID;        /* The Edit Menu ID                */
  124.     short                        undoTextResID;    /* The Undo 'STR#' resource id    */
  125.     UndoAction                    undoAction;        /* What is to be undone            */
  126.     void                        *refCon;        /* At the app's disposal        */
  127. } EditRecord, *EditPtr, **EditHandle;
  128.     
  129.     
  130. EditHandle                    CreateEditHandle(
  131.         const Rect                *viewRect,
  132.         short                    fontNumber,
  133.         short                    fontSize,
  134.         short                    editMenuID,
  135.         short                    undoTextResID,
  136.         void                    *refCon
  137.     );
  138. void                        DisposeEditHandle(
  139.         EditHandle                editHandle
  140.     );
  141. Boolean                        DoTextEditEvent(
  142.         EditHandle                editHandle,
  143.         const EventRecord        *eventRecord
  144.     );
  145.  
  146. Boolean                        AdjustEditMenu(
  147.         EditHandle                editHandle
  148.     );
  149. Boolean                        ManageEditMenu(
  150.         EditHandle                editHandle,
  151.         short                    menuItem        /* 1 = Undo, 3 = Cut, etc.    */
  152.     );
  153. void                        RepositionEditItem(
  154.         EditHandle                editHandle,
  155.         const Rect                *viewRect
  156.     );
  157. #define GetTEHandle(editHandle) ((**(editHandle)).teHandle)
  158. #endif /* __TextEditManager__ */
  159.  
  160.  
  161.  
  162.